home *** CD-ROM | disk | FTP | other *** search
/ Scene Storm / Scene Storm - Volume 1.iso / coding / asm / utils / satpic / satpic.alp < prev    next >
Text File  |  1980-01-03  |  12KB  |  608 lines

  1. ;+asm
  2. ;add lkopt SC
  3. ;do
  4. ;*
  5. ;
  6. ; ### WeatherSatelliteReceiver by JM v 1.00 ###
  7. ;
  8. ; - Created 910523 by JM -
  9. ;
  10. ;
  11. ; Usage:
  12. ;    sat [buf_siz]
  13. ;
  14. ;    where buf_siz is the raw buffer size (default 16384).
  15. ;
  16. ;
  17. ; Bugs: Hmm.  If you ask me, the hardware itself is a big bug.
  18. ;
  19. ;
  20. ; Edited:
  21. ;
  22. ; - 910523 by JM -> v0.01    - code from uBDitigizer.      | One year since.. |
  23. ; - 910524 by JM -> v0.02    - Opens a screen and a window.
  24. ; - 910525..910529        - Lots of modifications, it works now.
  25. ; - 910530 by JM -> v1.00    - All commands finished, code crunched and tested.
  26. ;                - Uses a command table instead of several cmp.b's.
  27. ;
  28.  
  29.  
  30.         include    "bb.i"
  31.         include    "exec/types.i"
  32.         include    "exec/execbase.i"
  33.         include    "exec/tasks.i"
  34.         include    "exec/nodes.i"
  35.         include    "exec/memory.i"
  36.         include    "exec/io.i"
  37.         include    "exec/strings.i"
  38.         include    "exec/interrupts.i"
  39.         include    "exec/initializers.i"
  40.         include    "hardware/intbits.i"
  41.         include    "hardware/cia.i"
  42.         include    "exec/interrupts.i"
  43.         include    "intuition/intuition.i"
  44.         include    "com.i"
  45.         include    "relative.i"
  46.         include    "util.i"
  47.         include    "macros.i"
  48. ;        include    "constants.i"
  49.         include    "hards.i"
  50.  
  51.         XREF    _LVOSetICR
  52.         XREF    _LVOAbleICR
  53.         XREF    _LVOAddICRVector
  54.         XREF    _LVORemICRVector
  55.  
  56. _LVOAllocMiscResource    equ    -6
  57. _LVOFreeMiscResource    equ    -12
  58. MR_PARALLELPORT    equ    2
  59.  
  60. userport    equ    $bfe101
  61. datadir        equ    $bfe301
  62. timerl        equ    $bfd400
  63. timerh        equ    $bfd500
  64. tcontrol    equ    $bfde00
  65. tint        equ    $bfdd00
  66.  
  67. HUGEMEM        equ    1000000000        -- never to be available --
  68.  
  69. ROWS        equ    512
  70. BYTESPERROW    equ    40
  71.  
  72.         .var    global
  73.         dlibb    Gfx,Intuition
  74.         dlibb    MiscRes,CIA
  75.         dl    DATA,data
  76.         dl    screen,window,begbuf,bufpoi,modulo
  77.         db    parport,int
  78.  
  79.         .local
  80.         .begin
  81.         ra
  82.         moveq    #0,d2            ; result
  83. =numlp        moveq    #0,d0
  84.         move.b    (a0)+,d0
  85.         sub.b    #'0',d0
  86.         blo.s    =numgot
  87.         cmp.b    #'9',d0
  88.         bhi.s    =numgot
  89.         add.l    d2,d2            ; d2 = old * 2
  90.         move.l    d2,d1            ; d1 = old * 2
  91.         add.l    d2,d2            ; d2 = old * 4
  92.         add.l    d2,d2            ; d2 = old * 8
  93.         add.l    d1,d2            ; d2 = old * 10
  94.         add.l    d0,d2            ; d2 = old * 10 + new
  95.         bra.s    =numlp
  96. =numgot        openlib    Gfx,=cleanup
  97.         openlib    Intuition,=cleanup
  98.  
  99.         move.l    #16384,d0
  100.         cmp.l    d0,d2
  101.         blo.s    =numerr            ; not a valid buffer size
  102.         move.l    d2,d0
  103. =numerr        move.l    d0,DATA            ; save buffer size
  104.  
  105.         moveq    #103,d7            ; out of memory
  106.         move.l    #MEMF_PUBLIC,d1
  107.         call    AllocMem
  108.         move.l    d0,data
  109.         beq    =cleanup
  110.         move.l    d0,a0
  111.         move.l    a0,begbuf
  112.         move.l    DATA,a2
  113.         subq.l    #4,a2
  114.         add.l    a0,a2            ; end address
  115.         moveq    #0,d5            ; start from color #0
  116. patloop0    moveq    #15,d4
  117. patloop1    moveq    #19,d3
  118.         move.l    d5,d0            ; color
  119. patloop2    moveq    #15,d2
  120. patloop3    move.b    d0,(a0)+        ; put 16 bytes of the same color
  121.         cmp.l    a2,a0
  122.         bhs    pattern_ok
  123.         dbf    d2,patloop3
  124.         add.w    #16,d0            ; change color
  125.         dbf    d3,patloop2
  126.         dbf    d4,patloop1
  127.         add.w    #16,d5
  128.         bra    patloop0
  129.  
  130. pattern_ok    move.w    #202,d7            ; cant get parallel port
  131.         bsr    allocparallel
  132.         bne    =cleanup
  133.  
  134.         moveq    #0,d0
  135.         lea    nscreen(pc),a1
  136.         lea    NS,a2
  137.         call    InitStruct
  138.  
  139.         moveq    #104,d7            ; cannot OpenScreen()
  140.         move.l    a2,a0
  141.         call    OpenScreen
  142.         move.l    d0,screen
  143.         beq    =cleanup
  144.         move.l    d0,a2
  145.         lea    sc_ViewPort(a2),a0
  146.         lea    colors(pc),a1
  147.         moveq    #16,d0
  148.         call    LoadRGB4
  149.  
  150.         moveq    #106,d7            ; cannot OpenWindow()
  151.         moveq    #0,d0
  152.         lea    nwindow(pc),a1
  153.         lea    NW,a2
  154.         call    InitStruct
  155.         move.l    a2,a0
  156.         move.l    screen,nw_Screen(a0)
  157.         call    OpenWindow
  158.         move.l    d0,window
  159.         beq    =cleanup
  160.  
  161.         move.l    #(BYTESPERROW*8*256),modulo
  162.  
  163.         moveq    #127,d7
  164.         bsr    allocint
  165.         bne    =cleanup
  166.  
  167. =waitloop    bsr    geti
  168.         bmi    =away
  169.         beq    =waitloop
  170.         tst.b    d0
  171.         bmi    =waitloop        ; key UP
  172.  
  173. =handle        lea    =cmdtable(pc),a2    ; RAW.B, QUAL.B, ADR.W
  174. =handlecmp    move.b    (a2)+,d2        ; get rawkey code
  175.         beq.s    =waitloop        ; not found
  176.         cmp.b    d2,d0            ; entry = key pressed?
  177.         beq.s    =handlefnd        ; yep -> check qualifier
  178.         addq.l    #3,a2            ; nope -> next entry
  179.         bra.s    =handlecmp
  180. =handlefnd    move.b    (a2)+,d2        ; get qualifier from table
  181.         beq.s    =handledoit        ; zero -> don't care, do it
  182.         and.b    d1,d2            ; non-zero: perform and
  183.         bne.s    =handledoit        ; yep, go do it
  184.         addq.l    #2,a2            ; nope, try next one
  185.         bra.s    =handlecmp
  186. =handledoit    moveq    #0,d2            ; clear d2
  187.         add.w    (a2),a2            ; get jump address
  188.         jmp    (a2)
  189.  
  190. =cmdtable    dc.b    $45,0            ; ESC
  191.         dptr    =away
  192.         dc.b    $22,0            ; D
  193.         dptr    =Cdigi
  194.         dc.b    $4f,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift left
  195.         dptr    =CSleft
  196.         dc.b    $4e,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift right
  197.         dptr    =CSright
  198.         dc.b    $2d,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift num4
  199.         dptr    =CSnum4
  200.         dc.b    $2f,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift num 6
  201.         dptr    =CSnum6
  202.         dc.b    $2e,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift num 5
  203.         dptr    =CSnum5
  204.         dc.b    $2d,IEQUALIFIER_LALT!IEQUALIFIER_RALT      ; alt num 4
  205.         dptr    =CAnum4
  206.         dc.b    $2f,IEQUALIFIER_LALT!IEQUALIFIER_RALT      ; alt num 6
  207.         dptr    =CAnum6
  208.         dc.b    $4c,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift up
  209.         dptr    =CSup
  210.         dc.b    $4d,IEQUALIFIER_LSHIFT!IEQUALIFIER_RSHIFT ; shift down
  211.         dptr    =CSdown
  212.         dc.b    $4c,IEQUALIFIER_LALT!IEQUALIFIER_RALT      ; alt up
  213.         dptr    =Creset
  214.         dc.b    $4d,IEQUALIFIER_LALT!IEQUALIFIER_RALT      ; alt down
  215.         dptr    =Creset
  216.  
  217.         dc.b    $4c,0            ; cursor up
  218.         dptr    =Cup
  219.         dc.b    $4d,0            ; cursor down
  220.         dptr    =Cdown
  221.         dc.b    $4f,0            ; cursor left
  222.         dptr    =Cleft
  223.         dc.b    $4e,0            ; cursor right
  224.         dptr    =Cright
  225.         dc.b    $2d,0            ; numeric pad 4
  226.         dptr    =Cnum4
  227.         dc.b    $2f,0            ; numeric pad 6
  228.         dptr    =Cnum6
  229.         dc.b    $2e,0            ; numeric pad 5
  230.         dptr    =Cnum5
  231.         dc.b    $40,0            ; space
  232.         dptr    =Cspace
  233.         dc.w    0
  234.  
  235. =CSright    moveq    #31,d2            ; step = 32 pixels
  236. =Cright        addq.l    #1,d2            ; step =  1 pixel
  237.         bra.s    =startadr
  238. =CSleft        moveq    #-31,d2            ; step = -32 pixels
  239. =Cleft        subq.l    #1,d2            ; step =  -1 pixel
  240. =startadr    move.l    begbuf,d1
  241.         add.l    d2,d1
  242.         cmp.l    data,d1
  243.         bhs.s    =starta_ok
  244.         move.l    data,d1            ; set to data if too low
  245. =starta_ok    move.l    d1,begbuf
  246. =Cspace        bsr    convert
  247.         bmi    =away
  248.         beq    =waitloop
  249.         bra    =handle
  250. =CSup        move.w    #-9920,d2        ; step = -10240 pixels
  251. =Cup        sub.w    #320,d2            ; step = -320 pixels
  252.         ext.l    d2
  253.         bra.s    =startadr
  254. =CSdown        move.w    #9920,d2        ; step = -10240 pixels
  255. =Cdown        add.w    #320,d2            ; step = 320 pixels
  256.         bra.s    =startadr
  257. =Cnum4        moveq    #-64,d2
  258.         bra.s    =modulo
  259. =Cnum6        moveq    #64,d2
  260. =modulo        move.l    modulo,d1
  261.         add.l    d2,d1
  262.         bpl    =modulo_ok
  263.         moveq    #0,d1            ; set to 0 if too low
  264. =modulo_ok    move.l    d1,modulo
  265.         bra    =Cspace
  266. =CSnum4        move.w    #-768,d2
  267.         ext.l    d2
  268.         bra.s    =modulo
  269. =CSnum6        move.w    #768,d2
  270.         bra.s    =modulo
  271. =CAnum4        moveq    #-1,d2
  272.         bra.s    =modulo
  273. =CAnum6        moveq    #1,d2
  274.         bra.s    =modulo
  275. =Creset        move.l    data,begbuf
  276. =Cnum5        move.l    #(BYTESPERROW*8*256),modulo
  277.         bra    =Cspace
  278. =CSnum5        move.l    #(BYTESPERROW*16*256),modulo
  279.         bra    =Cspace
  280.  
  281. =Cdigi        bsr    geti
  282.         bmi.s    =away
  283.         cmp.b    #($22!$80),d0
  284.         bne.s    =Cdigi
  285.         bsr    digitize
  286.         bra    =Cspace
  287.  
  288. =away        moveq    #0,d7
  289. =cleanup    bsr    freeint
  290.  
  291.         move.l    data,d0
  292.         .if    ne
  293.          move.l    d0,a1
  294.          move.l    DATA,d0
  295.          call    FreeMem
  296.         .end
  297.  
  298.         move.l    window,d0
  299.         .if    ne
  300.          move.l    d0,a0
  301.          call    CloseWindow
  302.         .end
  303.         move.l    screen,d0
  304.         .if    ne
  305.          move.l    d0,a0
  306.          call    CloseScreen
  307.         .end
  308.         bsr    freeparallel
  309.         closlib    Intuition
  310.         closlib    Gfx
  311.         move.l    d7,d0
  312.         .end    begin
  313.         .end    local
  314.  
  315.  
  316.  
  317. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  318.  
  319. geti        .local
  320.         .subr    d2-d3/a0-a2
  321.         move.l    window,a0
  322.         move.l    wd_UserPort(a0),a2
  323.         move.b    MP_SIGBIT(a2),d2
  324.         moveq    #0,d0
  325.         bset    d2,d0            set mp_SigBit
  326.         bset    #12,d0            set ctrl_c
  327.         call    Wait
  328.         btst    d2,d0
  329.         beq    =ctrlc
  330.         move.l    window,a0
  331.         move.l    wd_UserPort(a0),a2
  332.         move.l    a2,a0
  333.         fcall    GetMsg
  334.         tst.l    d0
  335.         beq.s    =nutton
  336.         move.l    d0,a1
  337.         moveq    #0,d2
  338.         moveq    #0,d3
  339.         cmp.l    #RAWKEY,im_Class(a1)
  340.         bne.s    =reply
  341.         move.w    im_Code(a1),d2
  342.         move.w    im_Qualifier(a1),d3
  343. =reply        fcall    ReplyMsg
  344.  
  345. =eat        move.l    a2,a0            ; eat extra messages
  346.         fcall    GetMsg
  347.         tst.l    d0
  348.         .if    ne
  349.          move.l    d0,a1
  350.          fcall    ReplyMsg
  351.          bra    =eat
  352.         .end
  353.         move.l    d3,d1            ; return Qualifier
  354.         move.l    d2,d0             ; return a rawkey
  355.         bra.s    =out
  356. =ctrlc        moveq    #-1,d0
  357.         bra.s    =out
  358. =nutton        moveq    #0,d0
  359. =out        .end     subr
  360.         .end    local
  361.  
  362.  
  363. allocparallel    .local
  364.         move.l    #HUGEMEM,d0        kick out the parallel.device!
  365.         move.l    d0,d2
  366.         moveq    #MEMF_PUBLIC,d1
  367.         call    AllocMem
  368.         tst.l    d0
  369.         beq.s    =notgot
  370.         move.l    d0,a1
  371.         move.l    d2,d0
  372.         fcall    FreeMem
  373.  
  374. =notgot        lea.s    'misc.resource',a1
  375.         moveq.l    #0,d0
  376.         fcall    OpenResource
  377.         move.l    d0,.MiscResBase
  378.         beq    =error
  379.  
  380.         moveq.l    #MR_PARALLELPORT,d0
  381.         lea    prgname(pc),a1
  382.         move.l    .MiscResBase,a6
  383.         jsr    _LVOAllocMiscResource(a6)
  384.         tst.l    d0
  385.         bne.s    =error
  386.         st    parport
  387.         move.b    d0,datadir        set port as input
  388.         rts                .ne if error
  389. =error        moveq    #1,d0
  390.         rts
  391.         .end
  392.  
  393.  
  394.  
  395. freeparallel    .local
  396.         tst.b    parport
  397.         .if    ne
  398.          moveq    #MR_PARALLELPORT,d0
  399.          move.l    .MiscResBase,a6
  400.          jsr    _LVOFreeMiscResource(a6)
  401.         .end
  402.         rts
  403.         .end
  404.  
  405.  
  406. allocint    .local
  407.         lea.s    'ciab.resource',a1
  408.         call    OpenResource
  409.         move.l    d0,.CIABase
  410.  
  411.         call    Disable
  412.         lea    interr,a1
  413.         move.b    #NT_INTERRUPT,LN_TYPE(a1)
  414.         lea    prgname(pc),a0
  415.         move.l    a0,LN_NAME(a1)
  416.         lea    irqcode(pc),a0
  417.         move.l    a0,IS_CODE(a1)        ; addr of irq routine
  418.         moveq    #CIAICRB_TA,d0        ; we want timer A
  419.         call    AddICRVector
  420.         move.l    d0,d2
  421.         bne    =error
  422.  
  423.         moveq    #1,d0
  424.         fcall    AbleICR            ; disable interrupt
  425.  
  426.         moveq    #1,d0
  427.         fcall    SetICR            ; clear interrupt
  428.  
  429.         call    Enable
  430.         st    int
  431.         moveq    #0,d0
  432.         rts
  433. =error        call    Enable
  434.         moveq    #-1,d0            ; error
  435.         rts
  436.         .end    local
  437.  
  438. freeint        .local
  439.         tst.b    int
  440.         .if    ne
  441.          moveq    #CIAICRB_TA,d0
  442.          lea    interr,a1
  443.          call    RemICRVector
  444.         .end
  445. irqcode        rts                ; kludge, int doesn't do anything
  446.         .end    local
  447.  
  448.  
  449.  
  450. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  451.  
  452.         .local
  453. digitize    .subr
  454.         call    Disable            ; 709379 kHz
  455.         move.b    #68,timerl        ; /8samples/320pixels/4Hz
  456.         move.b    #0,timerh
  457.         or.b    #$01,tcontrol        ; start timer A
  458.  
  459.         lea    userport,a0        ; source
  460.         move.l    data,a1            ; destination
  461.         move.l    a1,begbuf
  462.         move.l    #(BYTESPERROW*8*256),modulo
  463.         lea    tint,a2
  464.         move.l    DATA,d2            ; # of bytes
  465.  
  466.         move.w    #$80,d1
  467. =dloop        moveq    #7,d3            ; sample #
  468.         moveq    #0,d7            ; clear sum
  469.         btst    #0,(a2)
  470.         beq.s    =dwait
  471.         move.w    #$f00,$dff180
  472.         bra.s    =dbusy
  473.  
  474. =dwait        btst    #0,(a2)
  475.         beq.s    =dwait
  476.  
  477. =dbusy        moveq    #0,d0
  478.         move.b    (a0),d0
  479.         sub.w    d1,d0            ; sub mid level
  480.         bpl.s    =dwok            ; positive?
  481.         neg.w    d0            ; no, make it
  482. =dwok        add.w    d0,d7            ; sum
  483.         dbf    d3,=dwait        ; do for 8 samples
  484.         lsr.w    #2,d7            ; shift sum
  485.         move.b    d7,(a1)+        ; save sample
  486.         subq.l    #1,d2
  487.         bne.s    =dloop
  488.  
  489.         fcall    Enable
  490.  
  491.         .end    subr
  492.         .end    local
  493.  
  494.  
  495.         .local
  496. convert        .subr
  497.         clr.l    bufpoi
  498.         move.l    window,a0
  499.         move.l    wd_UserPort(a0),a0
  500.         move.b    MP_SIGBIT(a0),d7    ; sigbit
  501.         lbase    Exec
  502.  
  503.         move.l    screen,a2
  504.         lea    sc_RastPort(a2),a2    ; rp
  505.         move.l    rp_BitMap(a2),a2    ; bitmap
  506.         lea.l    bm_Planes(a2),a5    ; planeptrs
  507.         movem.l    (a5),a0-a3        ; get plane pointrs
  508.         move.l    begbuf,a5        ; source dataptr
  509.         move.w    #ROWS-1,d6        ; rows per plane
  510.  
  511. =rowloop    swap    d6
  512.         move.w    #(BYTESPERROW/2-1),d6    ; words to write per row
  513. =byteloop    moveq    #15,d5            ; bit counter
  514. =bitloop    move.b    (a5)+,d4        ; data byte
  515.         roxr.b    #5,d4
  516.         roxl.w    #1,d0            ; plane 0
  517.         roxr.b    #1,d4
  518.         roxl.w    #1,d1            ; plane 1
  519.         roxr.b    #1,d4
  520.         roxl.w    #1,d2            ; plane 2
  521.         roxr.b    #1,d4
  522.         roxl.w    #1,d3            ; plane 3
  523.         dbf    d5,=bitloop
  524.  
  525.         move.w    d0,(a0)+
  526.         move.w    d1,(a1)+
  527.         move.w    d2,(a2)+
  528.         move.w    d3,(a3)+
  529.         dbf    d6,=byteloop
  530.  
  531.         moveq    #0,d0
  532.         moveq    #0,d1
  533.         push    a0-a1
  534.         fcall    SetSignal        ; user activity?
  535.         pull    a0-a1
  536.         btst    d7,d0
  537.         beq.s    =go_on
  538.         bsr    geti
  539.         bmi.s    =away
  540.         tst.b    d0
  541.         bpl.s    =away            ; got a new rawkey
  542.  
  543. =go_on        move.l    begbuf,a5        ; restore buffer start address
  544.         move.l    modulo,d0
  545.         move.l    bufpoi,d1
  546.         add.l    d0,d1
  547.         move.l    d1,bufpoi
  548.         asr.l    #8,d1
  549.         add.l    d1,a5
  550.  
  551.         swap    d6
  552.         dbf    d6,=rowloop
  553.  
  554.         moveq    #0,d0
  555. =away        .end    subr
  556.         .end    local
  557.  
  558.  
  559.  
  560. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  561.  
  562. iniword        MACRO    * &offset,&value
  563.         DC.B    $90
  564.         DC.B    \1
  565.         DC.W    \2
  566.                 ENDM
  567.         
  568. inilong        MACRO    * &offset,&value
  569.         DC.B    $80
  570.         DC.B    \1
  571.         DC.L    \2
  572.                 ENDM
  573.         
  574. nscreen        iniword    ns_Width,BYTESPERROW*8
  575.         iniword    ns_Height,ROWS
  576.         iniword    ns_Depth,4
  577.         iniword    ns_DetailPen,-1
  578.         iniword    ns_ViewModes,V_SPRITES!V_LACE
  579.         iniword    ns_Type,CUSTOMSCREEN!SCREENQUIET
  580.         dc.w    0
  581.  
  582. nwindow        iniword    nw_Width,BYTESPERROW*8
  583.         iniword    nw_Height,ROWS
  584.         iniword    nw_DetailPen,-1
  585.         inilong    nw_IDCMPFlags,RAWKEY
  586.         inilong    nw_Flags,ACTIVATE!BORDERLESS!BACKDROP
  587.         iniword    nw_Type,CUSTOMSCREEN
  588.         dc.w    0
  589.  
  590. colors        dc.w    $0000,$0111,$0222,$0333,$0444,$0555,$0666,$0777
  591.         dc.w    $0888,$0999,$0aaa,$0bbb,$0ccc,$0ddd,$0eee,$0fff
  592.  
  593. prgname        dc.b    'sat',0
  594.  
  595.         .purge
  596.  
  597.         section    hyi,bss
  598.  
  599. NS    ds.b    ns_SIZEOF
  600. NW    ds.b    nw_SIZE
  601. interr    ds.b    IS_SIZE
  602.  
  603.  
  604.         end
  605.  
  606.  
  607.  
  608.